package com.weijianhuawen.wjblog.common.utils;

import java.util.regex.Pattern;

/**
 * @version: java version 17
 * @Author: weijianhuawen
 * @description:
 * @date: 2025-04-26 17:51
 */
public final class ValidateUtil {
    private ValidateUtil() {

    }
    // 定义手机号长度
    private static final int PHONE_NUMBER_LENGTH = 11;
    // 手机验证正则表达式
    private static final String PHONE_NUMBER_REGEX = "^1[3-9]\\d{9}$";

    // 手机号校验
    public static boolean isPhoneNumber(String phoneNumber) {
        if (phoneNumber == null || phoneNumber.length() != PHONE_NUMBER_LENGTH) {
            return false;
        }
        // 手机号正则表达式
        Pattern pattern = Pattern.compile(PHONE_NUMBER_REGEX);
        return pattern.matcher(phoneNumber).matches();
    }

    // qq 号码长度范围
    // 最小值
    private static final int QQ_NUMBER_MIN_LENGTH = 5;
    // 最大值
    private static final int QQ_NUMBER_MAX_LENGTH = 16;
    // 定义 qq 号码正则表达式
    private static final String QQ_NUMBER_REGEX = "^[1-9]\\d{4,15}$";
    // qq 号码校验
    public static boolean isQqNumber(String qqNumber) {
        if (qqNumber == null || qqNumber.length() < QQ_NUMBER_MIN_LENGTH || qqNumber.length() > QQ_NUMBER_MAX_LENGTH) {
            return false;
        }
        // 手机号正则表达式
        Pattern pattern = Pattern.compile(QQ_NUMBER_REGEX);
        return pattern.matcher(qqNumber).matches();
    }

    // 邮箱长度范围
    // 最小值
    private static final int EMAIL_MIN_LENGTH = 5;
    // 最大值
    private static final int EMAIL_MAX_LENGTH = 128;
    // 定义邮箱正则表达式
    private static final String EMAIL_REGEX = "^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\\.[a-zA-Z0-9_-]+)+$";
    // 邮箱校验
    public static boolean isEmail(String email) {
        if (email == null || email.length() < EMAIL_MIN_LENGTH || email.length() > EMAIL_MAX_LENGTH) {
            return false;
        }
        // 邮箱正则表达式
        Pattern pattern = Pattern.compile(EMAIL_REGEX);
        return pattern.matcher(email).matches();
    }

    // 账号密码格式
    // 账号长度范围
    // 最小值
    private static final int ACCOUNT_MIN_LENGTH = 6;
    // 最大值
    private static final int ACCOUNT_MAX_LENGTH = 16;
    // 定义账号正则表达式：大小字母，数字，特殊字符（下划线，中划线，&, %, @）
    private static final String ACCOUNT_REGEX = "^[a-zA-Z0-9_&%@-]{6,16}$";
    // 账号校验
    public static boolean isAccount(String account) {
        if (account == null || account.length() < ACCOUNT_MIN_LENGTH || account.length() > ACCOUNT_MAX_LENGTH) {
            return false;
        }
        // 账号正则表达式
        Pattern pattern = Pattern.compile(ACCOUNT_REGEX);
        return pattern.matcher(account).matches();
    }

    // 密码格式
    // 密码长度范围
    // 最小值
    private static final int PASSWORD_MIN_LENGTH = 8;
    // 最大值
    private static final int PASSWORD_MAX_LENGTH = 18;
    // 定义密码正则表达式：大小字母，数字，特殊字符（下划线，中划线，&, %, @）
    private static final String PASSWORD_REGEX = "^[a-zA-Z0-9_&%@-]{8,18}$";
    // 密码校验
    public static boolean isPassword(String password) {
        if (password == null || password.length() < PASSWORD_MIN_LENGTH || password.length() > PASSWORD_MAX_LENGTH) {
            return false;
        }
        // 密码正则表达式
        Pattern pattern = Pattern.compile(PASSWORD_REGEX);
        return pattern.matcher(password).matches();
    }

}
